package com.wm.ad_navi_new.skin

import android.view.View

abstract class AbstractSkinAttr : Cloneable {

    private val RES_TYPE_NAME_COLOR = "color"
    private val RES_TYPE_NAME_DRAWABLE = "drawable"
    private val RES_TYPE_NAME_MIPMAP = "mipmap"

    /**
     * 属性名称：textColor，background
     */
    var attrName: String? = null

    /**
     * attribute reference id
     * 属性id
     *
     */
    var attrValueRefId = 0

    /**
     * type of the value , such as color or drawable
     * 类型，如颜色或可绘制
     *
     */
    var attrValueTypeName: String? = null


    /**
     * resources name, eg:app_exit_btn_background
     * 资源名称, 如:app_exit_btn_background
     *
     */
    var attrValueRefName: String? = null

    protected abstract fun applySkin(view: View?)

    protected open fun isColor(): Boolean {
        return RES_TYPE_NAME_COLOR == attrValueTypeName
    }

    protected open fun isDrawable(): Boolean {
        return RES_TYPE_NAME_DRAWABLE == attrValueTypeName || RES_TYPE_NAME_MIPMAP == attrValueTypeName
    }

    /**
     * Use to apply view with new TypedValue
     * 应用具有新的视图，换肤的具体视图
     *
     * @param view view
     */
    open fun apply(view: View?) {
        applySkin(view)
    }

    public override fun clone(): Any {
        return super.clone()
        var o: AbstractSkinAttr? = null
        try {
            o = super.clone() as AbstractSkinAttr
        } catch (e: CloneNotSupportedException) {
            e.printStackTrace()
        }
        return o!!
    }


}